describe("日志中心", () => {
  beforeEach(() => {
    const username = "admin";
    const password = "123456";
    cy.login(username, password);

    cy.intercept("POST", "/api/robot-archives/v1/getCompanyRobotList").as(
      "getCompanyRobotList"
    );

    cy.visit("/disinfect/log-center");
  });

  it("进入日志中心-页面显示", () => {
    // 判断页面表头信息是否正确
    let tableTh = [
      "编号",
      "机器人型号",
      "机器人唯一码",
      "上线时间",
      "更新时间",
      "状态",
      "故障信息",
    ];
    cy.get("table>thead>tr>th").should("have.length", tableTh.length);
    for (let i = 0; i < tableTh.length; i++) {
      cy.contains(tableTh[i]);
    }
    // 判断表格数据条数是否大于0
    cy.get("table>tbody>tr").then(($tr) => {
      expect($tr.length).to.greaterThan(0);
    });

    cy.contains("查看故障历史");
  });

  it("故障历史-页面显示", () => {
    openFaultHistory();
    // 判断页面表头信息是否正确
    let tableTh = ["编号", "故障内容", "发生时间", "故障快照"];
    cy.get("table>thead>tr>th").should("have.length", tableTh.length);
    for (let i = 0; i < tableTh.length; i++) {
      cy.contains(tableTh[i]);
    }
    //
    cy.get("table>tbody>tr").then(($tr) => {
      expect($tr.length).to.greaterThan(0);
    });

    // cy.contains("暂无数据");
  });

  it("故障快照（机器人详情）-页面显示", () => {
    openFaultHistory();
    cy.intercept(
      "GET",
      "http://localhost:5173/api/robot-log/v1/disinfect/*"
    ).as("getRobotDetails");
    cy.get("table>tbody>tr").contains("故障快照").click();

    cy.wait("@getRobotDetails");

    cy.getByData("robot-statu").contains("故障");
  });
});

function openFaultHistory() {
  cy.wait("@getCompanyRobotList");
  cy.intercept("GET", "/api/robot-disinfect-fault-snapshot/v1/*").as(
    "getFaultHistory"
  );
  cy.get("table>tbody>tr").eq(5).contains("查看故障历史").click();
  cy.wait("@getFaultHistory");
}
